package com.tulingxueyuan.mall.modules.fms.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tulingxueyuan.mall.modules.fms.mapper.FmsFactoryMapper;
import com.tulingxueyuan.mall.modules.fms.model.FmsFactory;
import com.tulingxueyuan.mall.modules.fms.model.dto.FactoryConditionDTO;
import com.tulingxueyuan.mall.modules.fms.service.FmsFactoryService;
import com.tulingxueyuan.mall.modules.pms.model.PmsProductFarmer;
import com.tulingxueyuan.mall.modules.pms.model.dto.ProductFarmerConditionDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Bin
 * @since 2022-09-07
 */
@Service
public class FmsFactoryServiceImpl extends ServiceImpl<FmsFactoryMapper, FmsFactory> implements FmsFactoryService {

    @Autowired
    FmsFactoryMapper factoryMapper;

    /**
     * 获取农户列表-数据列表数据（重写）
     * @param condition
     * @return
     */
    @Override
    public Page list(FactoryConditionDTO condition) {
        Page page = new Page(condition.getPageNum(), condition.getPageSize());
        QueryWrapper<FmsFactory> queryWrapper = new QueryWrapper<>();
        LambdaQueryWrapper<FmsFactory> lambdaQueryWrapper = queryWrapper.lambda();
        // 工厂名（模糊查询）
        if (!StrUtil.isBlank(condition.getName())){
            lambdaQueryWrapper.like(FmsFactory::getName,condition.getName());
        }
        // 负责人（模糊查询）
        if (!StrUtil.isBlank(condition.getPrincipalName())){
            lambdaQueryWrapper.like(FmsFactory::getPrincipalName,condition.getPrincipalName());
        }
        // 生产方式
        if (condition.getProductionMode()!=null){
            lambdaQueryWrapper.eq(FmsFactory::getProductionMode,condition.getProductionMode());
        }
        return this.page(page,lambdaQueryWrapper);
    }

}
